//
//  NMTypeViewController.m
//  HNJYB
//
//  Created by Mag1cPanda on 2017/3/21.
//  Copyright © 2017年 Mag1cPanda. All rights reserved.
//

#import "NMTypeViewController.h"
#import "JCAlertView.h"
#import "PZNCCell.h"
#import "SRBlockButton.h"
#import "AccidentHeader.h"
//#import "NonMotorViewController.h"
#import "NMNMViewController.h"
#import "MNMViewController.h"

@interface NMTypeViewController ()
<UITableViewDataSource,
UITableViewDelegate>
{
    AccidentHeader *header;
    UITableView *table;
    NSArray *iconArr;
    NSArray *titleArr;
    JCAlertView *jcAlert;
}

@end

@implementation NMTypeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"选择事故类型";
    iconArr = @[@"mnm", @"nmnm"];
    titleArr = @[@"机动车与非机动车事故", @"非机动车与非机动车事故"];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 45, 30);
    [backBtn addTarget:self action:@selector(backAction) forControlEvents:1 << 6];
    
    UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 18, 13)];
    icon.image = [UIImage imageNamed:@"IP020"];
    icon.center = backBtn.center;
    [backBtn addSubview:icon];
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = item;
    
    header = [[AccidentHeader alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 100)];
    header.icon.image = [UIImage imageNamed:@"IP013"];
    header.topLab.text = @"请您在保证自身安全的情况下操作";
    header.bottemLab.text = @"请选择事故类型";
    [self.view addSubview:header];
    
    table = [[UITableView alloc] initWithFrame:CGRectMake(10, 100, ScreenWidth - 20, ScreenHeight - 164) style:UITableViewStylePlain];
    table.tableFooterView = [UIView new];
    table.backgroundColor = HNBackColor;
    table.delegate = self;
    table.dataSource = self;
    table.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:table];
    
    [table registerNib:[UINib nibWithNibName:@"PZNCCell" bundle:nil] forCellReuseIdentifier:@"PZNCCell"];
}

#pragma mark - tableView Delegate & DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PZNCCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PZNCCell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.icon.image = [UIImage imageNamed:iconArr[indexPath.section]];
    cell.contentLab.text = titleArr[indexPath.section];
    cell.contentLab.font = [UIFont systemFontOfSize:13];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth - 20, 10)];
    view.backgroundColor = HNBackColor;
    return view;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    //机动车与非机动车
    if (indexPath.section == 0)
    {
        MNMViewController *vc = [MNMViewController new];
        GlobleInstance.caseType = HNCaseTypeMNM;
        [self.navigationController pushViewController:vc animated:YES];
    }
    //非机动车与非机动车
    else {
        NMNMViewController *vc = [NMNMViewController new];
        GlobleInstance.caseType = HNCaseTypeNMNM;
        [self.navigationController pushViewController:vc animated:YES];
    }
}


@end
